package luj.tool.jnproxyan.proxy.network.socks.reply;

import io.netty.buffer.ByteBuf;
import luj.net.api.server.ConnectionAcceptInitializer;
import luj.tool.jnproxyan.proxy.network.socks.request.SocksRequest;
import org.springframework.stereotype.Component;

@Deprecated
@Component
public class SocksConnectReplier {

  public SocksConnectReplier inject(SocksRequest req) {
    return inject(req.getC2pConn());
  }

  public SocksConnectReplier inject(ConnectionAcceptInitializer.Connection conn) {
    var result = new SocksConnectReplier();
    result._conn = conn;
    return result;
  }

  public void replySuccess() {
    ByteBuf buf = new SocksReplyMaker(_conn).make(SUCCEEDED);

    _conn.write(buf);
    _conn.flush();
  }

  private static final int SUCCEEDED = 0x00;

  ConnectionAcceptInitializer.Connection _conn;
}
